package com.yhsoft.wxprogram.controller;

import com.yhsoft.benefitcard.service.ICardsInfoService;
import com.yhsoft.common.vo.Result;
import com.yhsoft.wxprogram.controller.request.BindingCardInVo;
import com.yhsoft.wxprogram.controller.request.SetCardInUseInVo;
import com.yhsoft.wxprogram.controller.response.BenefitCardOutVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: yyyyyyyh
 * @create: 2023-10-13
 * @Version 1.0
 **/
@Api(tags = {"G-wx-我的福利卡，卡券接口"})
@RestController
@RequestMapping("/wxApi/cards/")
public class WxMyCardsController {

    @Autowired
    private ICardsInfoService iCardsInfoService;

    // 绑定福利卡
    @ApiOperation("绑定福利卡")
    @PostMapping("/bindingCard")
    public Result<?> bindingCard(@Valid @RequestBody BindingCardInVo inVo) {
        String msg = iCardsInfoService.bindingCard(inVo.getCardNum(), inVo.getCardPassword());
        if("绑定成功！".equals(msg)){
            return Result.success(msg);
        }
        return Result.fail(msg);
    }

    @ApiOperation("查询我的福利卡")
    @GetMapping("/getBenefitCard")
    public Result<List<BenefitCardOutVo>> getBenefitCard() {
        List<BenefitCardOutVo> list = iCardsInfoService.getBenefitCard();
        return Result.success(list);
    }

    @ApiOperation("设置使用中福利卡")
    @PostMapping("/setCardInUse")
    public Result<?> setCardInUse(@Valid @RequestBody SetCardInUseInVo inVo) {
        iCardsInfoService.setCardInUse(inVo.getCardId());
        return Result.success("设置成功！");
    }

    @ApiOperation("获取使用中福利卡")
    @GetMapping("/getInUseCard")
    public Result<BenefitCardOutVo> getInUseCard(){
        BenefitCardOutVo outVo = iCardsInfoService.getInUseCard();
        if(outVo == null){
            return Result.fail("未获取到使用中的福利卡！");
        }
        return Result.success(outVo);
    }

    @ApiOperation("获取可支付的福利卡")
    @GetMapping("/getCanPayCards")
    public Result<List<BenefitCardOutVo>> getCanPayCards(@RequestParam(value = "goodsId") Integer goodsId){
        List<BenefitCardOutVo> outVo = iCardsInfoService.getCanPayCards(goodsId);
        if(outVo == null){
            return Result.fail("未获取到使用中的福利卡！");
        }
        return Result.success(outVo);
    }

    @ApiOperation("我的券包")
    @GetMapping("/getExpenseCard")
    public Result<?> getExpenseCard() {

        return Result.success("");
    }
}
